/*
 * @Author: Turump 
 * @Date: 2021-03-31 10:29:01 
 * @Last Modified by: Turump
 * @Last Modified time: 2021-05-12 17:35:51
 * 出场任务
 */

import CocosHelper, { Direction } from "../helper/CocosHelper";
import { TaskBase } from "./TaskBase";

const { ccclass, property, menu } = cc._decorator;

@ccclass @menu("任务组件/出场")
export default class MoveOutTask extends TaskBase {

    @property({ displayName: "方向", type: cc.Enum(Direction) })
    direction: Direction = Direction.Right

    @property({ displayName: "出场时旋转乎?" })
    isRotateOut = false;
    @property({ displayName: "旋转角度(by)", visible() { return this.isRotateOut == true } })
    rotateAngle = 0;
    @property({ displayName: "出场动作时长" })
    actionDuration = 0.75;
    @property({ displayName: "remove self" })
    isRemoveSelf = true;

    enableTask() {
        super.enableTask();
        // CocosHelper.changeParent(this.node, cc.Canvas.instance.node);
        let pos = CocosHelper.getNodeOutScreenPosition(this.node, this.direction);
        cc.tween(this.node)
        .call(()=>{
        })
        .to(this.actionDuration, {
            position: cc.v3(pos),
            angle: this.node.angle + this.rotateAngle
        }).call(() => {
            this.emitDoneEvent();
            if (this.isRemoveSelf) {
                this.node.removeFromParent();
                this.node.destroy();
            }
        }).start();
    }
}
